<?php
namespace Admin\Controller;
use Common\Controller\AdminController;
/*
*
* 参赛申请
 */
class JlsbController extends AdminController{
	//动作名称
	private $_act_show = array(
		"0"	=> "奖励申报",
		"1"	=> "系部审核",
		"2"	=> "学校审核",
	);
	//0：环节进行中，1：当前环节结束
	private $_act_status = array(
		"0"	=> "进行中",
		"1"	=> "结束",
	);
	protected function _initialize(){
		parent::_initialize();
		$this->assign('_act_show', $this->_act_show);
		$this->assign('_act_status', $this->_act_status);
	}

	public function index(){
	   	$where = "1=1";
		$list = $this->getList('*', 'js_jlsb', $where, 'id desc', true);
 		$this->assign('list', $list);
	    $this->display();
	}
	/*参赛报名*/
	public function add(){
		if(IS_POST){
			$this->_autoSet();
			if(I('post.act_type') == "saveSubmit"){
				//更新立项申报表的环节信息
				$_POST['act_id'] 	= 1;	//环节1
				$_POST['status'] 	= 0;	//0：环节进行中，1：当前环节结束
			}
			$_POST['f9']=time();
			$result = $this->updateData($_POST, 'js_jlsb');
			$this->returnResult($result);
		}else{
			$this->display();
		}
	}	
   /**
	 * 参赛申报信息浏览
	 */
	public function select(){
		$info = $this->getInfo('*', 'js_jlsb', 'id=' . I('get.id', 0, 'intval'));
		$this->assign('info', $info);
		$list_yj = $this->getList('*', 'public_action', 'table_id=' . I('get.id', 0, 'intval'));
		$this->assign('list_yj', $list_yj);
		$this->display();
	}
	/**
	 * 参赛申报信息编辑
	 */
	public function edit(){
		if(IS_POST){
			$this->_autoSet();
			if(I('post.act_type') == "saveSubmit"){
				//更新立项申报表的环节信息
				$_POST['act_id'] 	= 1;	//环节1
				$_POST['status'] 	= 0;	//0：环节进行中，1：当前环节结束
			}
			$result = $this->updateData($_POST, 'js_jlsb', 2);
			$this->returnResult($result);
		}else{
			$info = $this->getInfo('*', 'js_jlsb', 'id=' . I('get.id', 0, 'intval'));
			$this->assign('info', $info);
			$this->display('add');
		}
	}
       /**
	 * 删除信息
	 */  
     public function del(){
		$result = $this->deleteData(array('id' => I('get.id', 0, 'intval')), 'js_jlsb');
		$this->returnResult($result);
	}
   /**
	 * 自动增加的信息
	 */
	private function _autoSet(){
		$_POST['uid']		= session('adminInfo.id');
		$_POST['user_name']	= session('adminInfo.name');
		$_POST['dep_id']	= '';
		$_POST['dep_name']	= '';
		$_POST['ctime'] 	= strtotime($_POST['times']);
		$_POST['status'] 	= '0';	//0：环节进行中，1：当前环节结束
	}


	private function _autoSetActInfo($_opt){
		$info_act = array(
			"dep_id"		=>	"",
			"dep_name"		=>	"",
			"uid"			=>	session('adminInfo.id'),
			"user_name"		=>	session('adminInfo.name'),
			"act_times"		=>	time(),
			"table_name"	=>	"js_jlsb",
		);
		return array_merge($_opt,$info_act);
	}

	/*系部管理*/
	public function xbgl(){
		$where = "act_id > 0 ";
		$list = $this->getList('*', 'js_jlsb', $where, 'id desc', true);
		$this->assign('list', $list);
		$this->display();
	}
   /**
	 * 删除信息
	 */  
    public function delxbgl_set(){
		$result = $this->deleteData(array('id' => I('get.id', 0, 'intval')), 'js_jlsb');
		$this->returnResult($result);
	}
    /*系部审核*/
	public function xbgl_set(){
			if(IS_POST){
			$_id 		= I('post.id', 0, 'intval');
			$_table_id 	= I('post.table_id', 0, 'intval');
			$_set_opt =	array(
				"id"			=>	$_id,
				"table_id"		=>	$_table_id,
				"act_content"	=>	I('post.act_content'),
				"act_remake"	=>	I('post.act_remake'),
				"status"		=>	I('post.act_type') == "saveSubmit"?1:0	//0：环节进行中，1：当前环节结束
			);
			$info_act = $this->_autoSetActInfo($_set_opt);
			$result = $this->updateData($info_act, 'public_action',2);

			if($result && I('post.act_type') == "saveSubmit"){
				//更新立项申报表的环节信息
				$_save =	array(
					"id"			=>	$_table_id,
					"act_id"		=>	"2",	//环节2
					"status" 		=>	"0",	//环节当前状态：待审核
					"act_times"		=>	time(),
				);
				$this->updateData($_save, 'js_jlsb', 2);
			}
			$this->returnResult($result,null,U("Jlsb/xbgl"));
		}else{
			$_table_id = I('get.id', 0, 'intval');
			$info = $this->getInfo('*', 'js_jlsb', 'id=' . $_table_id);
			$this->assign('info', $info);

			if($info['status'] == '0'){
				//更新立项申报表的环节信息
				$_save =	array(
					"id"			=>	$_table_id,
					"act_id"		=>	"1",	//环节1
					"status" 		=>	"0",	//环节当前状态：正在审核
					"act_times"		=>	time(),
				);
				$this->updateData($_save, 'js_jlsb', 2);
			}

			//自动产生默认审核信息
			$info_act = $this->getInfo('*', 'public_action', "table_name = 'js_jlsb' and act_id = 1 and table_id = ". $_table_id);
			if(is_null($info_act)){
				$_opt = array(
					"act_id"		=>	"1",
					"table_id"		=>	$_table_id
				);
				$info_act = $this->_autoSetActInfo($_opt);
				$result = $this->updateData($info_act, 'public_action');
				$info_act['id'] = $result;
			}
			$this->assign('info_act', $info_act);
			$this->display();
		}
	}

	/*学校管理*/
	public function xxgl(){
		$where = "act_id > 1";
		$list = $this->getList('*', 'js_jlsb', $where, 'id desc', true);
		$this->assign('list', $list);
		$this->display();
	}
     /**
	 * 删除信息
	 */  
     public function delxxgl_set(){
		$result = $this->deleteData(array('id' => I('get.id', 0, 'intval')), 'js_jlsb');
		$this->returnResult($result);
	}
	/*学校审核*/
	public function xxgl_set(){
		if(IS_POST){
			$_id 		= I('post.id', 0, 'intval');
			$_table_id 	= I('post.table_id', 0, 'intval');
			$_set_opt =	array(
				"id"			=>	$_id,
				"table_id"		=>	$_table_id,
				"act_content"	=>	I('post.act_content'),
				"act_remake"	=>	I('post.act_remake'),
				"status"		=>	I('post.act_type') == "saveSubmit"?1:0	//0：环节进行中，1：当前环节结束
			);
			$info_act = $this->_autoSetActInfo($_set_opt);
			$result = $this->updateData($info_act, 'public_action',2);

			if($result && I('post.act_type') == "saveSubmit"){
				//更新立项申报表的环节信息
				$_save =	array(
					"id"			=>	$_table_id,
					"act_id"		=>	"2",	//环节2
					"status" 		=>	"1",	//环节当前状态：审核结束
					"act_times"		=>	time(),
				);
				$this->updateData($_save, 'js_jlsb', 2);
			}
			$this->returnResult($result,null,U("Jlsb/xxgl"));
		}else{
			$_table_id = I('get.id', 0, 'intval');
			$info = $this->getInfo('*', 'js_jlsb', 'id=' . $_table_id);
			$this->assign('info', $info);

			if($info['status'] == '0'){
				//更新立项申报表的环节信息
				$_save =	array(
					"id"			=>	$_table_id,
					"act_id"		=>	"2",	//环节1
					"status" 		=>	"0",	//环节当前状态：正在审核
					"act_times"		=>	time(),
				);
				$this->updateData($_save, 'js_lxsb', 2);
			}

			//自动产生默认审核信息
			$info_act = $this->getInfo('*', 'public_action', "table_name = 'js_jlsb' and act_id = 2 and table_id = ". $_table_id);
			if(is_null($info_act)){
				$_opt = array(
					"act_id"		=>	"2",
					"table_id"		=>	$_table_id
				);
				$info_act = $this->_autoSetActInfo($_opt);
				$result = $this->updateData($info_act, 'public_action');
				$info_act['id'] = $result;
			}
			$this->assign('info_act', $info_act);
			$this->display();
		}
	}
}